package com.pengtu.entity.business.application;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Attachment;

/**
 * 质量监督受理通知书
 * 
 * @author liuyang
 * 
 */
@Entity
@Table(name = "T_Q_CASE_APPL_NOTICE")
public class ApplNotice extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String code; // 编号
	private String projId; // 工程
	private FlowApplication flowApplication; // 流程ID
	private String orgName; // 收文单位
	private Date noticeDate; // 通知时间
	private String content; // 通知书内容
	private String remark; // 备注
	private String acctPetitionFile; // 附件资料

	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			});
	
	private String did;//发文ID
	private String end;//是否办结
	private String cc;

	@Column(name = "CODE")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "PROJID")
	public String getProjId() {
		return projId;
	}

	public void setProjId(String projId) {
		this.projId = projId;
	}

	@ManyToOne(targetEntity = FlowApplication.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "FID")
	public FlowApplication getFlowApplication() {
		return flowApplication;
	}

	public void setFlowApplication(FlowApplication flowApplication) {
		this.flowApplication = flowApplication;
	}

	@Column(name = "ORGNAME")
	public String getOrgName() {
		return orgName;
	}

	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}

	@Column(name = "NOTICEDATE")
	public Date getNoticeDate() {
		return noticeDate;
	}

	public void setNoticeDate(Date noticeDate) {
		this.noticeDate = noticeDate;
	}

	@Column(name = "CONTENT")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "ACCTPETITIONFILE")
	public String getAcctPetitionFile() {
		return acctPetitionFile;
	}

	public void setAcctPetitionFile(String acctPetitionFile) {
		this.acctPetitionFile = acctPetitionFile;
	}
	
	@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}
	public void setAttachmentSet(Set<Attachment> attachmentSet) {
		this.attachmentSet = attachmentSet;
	}
	
	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}
	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}

	/**
	 * did
	 *
	 * @return  the did
	 * @since   1.0.0
	 */
	@Column(name="DID")
	public String getDid() {
		return did;
	}

	/**
	 * @param did the did to set
	 */
	public void setDid(String did) {
		this.did = did;
	}

	/**
	 * end
	 *
	 * @return  the end
	 * @since   1.0.0
	 */
	@Column(name="END")
	public String getEnd() {
		return end;
	}

	/**
	 * @param end the end to set
	 */
	public void setEnd(String end) {
		this.end = end;
	}

	/**
	 * cc
	 *
	 * @return  the cc
	 * @since   1.0.0
	 */
	@Column(name="CC")
	public String getCc() {
		return cc;
	}

	/**
	 * @param cc the cc to set
	 */
	public void setCc(String cc) {
		this.cc = cc;
	}
}
